<?php

namespace common\models\wechat;

use Yii;

/**
 * This is the model class for table "wechat_reply_rule".
 *
 * @property string $id
 * @property string $wid
 * @property string $name
 * @property string $module
 * @property string $displayorder
 * @property integer $status
 */
class WechatReplyRule extends \yii\db\ActiveRecord
{

    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '回复规则',      //用于修改了什么的显示
        'mainfield' => 'name',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];

    /**
     * 激活状态
     */
    const STATUS_ACTIVE = 1;
    /**
     * 禁用状态
     */
    const STATUS_DISABLED = 0;
    const PROCESSOR_DEFAULT = 'process';
    public static $statuses = [
        self::STATUS_ACTIVE => '启用',
        self::STATUS_DISABLED => '禁用'
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%wechat_reply_rule}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['wid', 'name', 'module', 'status','processor'], 'required'],
            [['wid', 'displayorder', 'status'], 'integer'],
            [['name', 'module' , 'processor'], 'string', 'max' => 50],
            [['displayorder', 'module' , 'processor','id'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'wid' => '公众号id',
            'name' => '规则名称',
            'module' => '模块',
            'displayorder' => '排序优先级',
            'status' => '状态',
        ];
    }

    public function getKeyword()
    {
        return $this->hasOne(WechatReplyKeyword::className(),['id','rid']);
    }

    public function getRule()
    {
        return $this->hasOne(WechatReplyRule::className(),['id'=>'rid']);
    }

}
